import type { DynamicProps } from '/#/utils';
import type { BasicTableProps, BasicColumn } from '/@/components/Table/src/types/table';
import { FormProps } from '/@/components/Table';
import { searchSchemas } from './searchData';
import { GetNonEquipmentList } from '/@/api/sys/gateway/gateway';
import { h } from 'vue';
type Props = Partial<DynamicProps<BasicTableProps>>;
// 列配置
const tableColumns: BasicColumn[] = [
  {
    title: '设备ID',
    dataIndex: 'id',
    width: 60,
  },
  {
    title: '自编码',
    dataIndex: 'code',
    width: 60,
  },
  {
    title: '子设备名称',
    dataIndex: 'name',
    width: 150,
  },

  {
    title: '设备编号/序列号',
    dataIndex: 'device_serial',
    width: 130,
  },
  {
    title: '品牌',
    dataIndex: 'brand_name',
    width: 100,
  },
  {
    title: '型号',
    dataIndex: 'device_type_name',
    width: 100,
  },
  {
    title: '状态',
    dataIndex: 'device_status',
    width: 100,
    customRender: ({ record }) => {
      if (record.device_status == 1) {
        return h('div', { style: { color: '#52C41A' } }, '在线');
      } else if (record.device_status == 0) {
        return h('div', { style: { color: '#FF5500' } }, '离线');
      } else {
        return h('div', { style: { color: 'orange' } }, '未知');
      }
    },
  },
  {
    title: '工艺状态',
    dataIndex: 'abnormal_status',
    width: 100,
    customRender: ({ record }) => {
      if (record.abnormal_status == '正常') {
        return h('div', { style: { color: '#52C41A' } }, record.abnormal_status);
      } else {
        return h('div', { style: { color: '#FF5500' } }, record.abnormal_status);
      }
    },
  },
];
export const formConfig: Partial<FormProps> = {
  schemas: searchSchemas,
  actionColOptions: {
    span: 5,
    style: { textAlign: 'left', marginLeft: '0px' },
  },
};
export const tableConfig: Props = {
  api: getData,
  columns: tableColumns,
  useSearchForm: true,
  formConfig: formConfig,
  showTableSetting: false,
  tableSetting: { fullScreen: false },
  showIndexColumn: false,
  rowKey: 'id',
  canResize: true,
  maxHeight: 350,
  bordered: true,
  striped: true,
  pagination: {
    showQuickJumper: false,
  },
  fetchSetting: {
    totalField: 'total',
    listField: 'list',
    sizeField: 'page_size',
  },
};
export async function getData(params: any): Promise<any> {
  const res = await GetNonEquipmentList(params);
  return res;
}
